package cn.ctbu.xiaopeng.studentscoremanage.service;

import cn.ctbu.xiaopeng.studentscoremanage.anno.Log;
import cn.ctbu.xiaopeng.studentscoremanage.dao.ClassesRepository;
import cn.ctbu.xiaopeng.studentscoremanage.pojo.entity.Classes;
import cn.ctbu.xiaopeng.studentscoremanage.pojo.vo.ClassesListVO;
import cn.hutool.core.bean.BeanUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xiaopeng
 * @version 1.0
 */
@Service
@RequiredArgsConstructor
public class ClassesService {
    private final ClassesRepository classesRepository;

    /**
     * 查询所有班级列表信息
     *
     * @return
     */
    @Log
    public List<ClassesListVO> getAll() {
        return BeanUtil.copyToList(classesRepository.findAll(), ClassesListVO.class);
    }


    /**
     * 根据班级编号查询班级名称
     *
     * @param classNo
     * @return
     */
    @Log
    public String findClassNameByClassNo(String classNo) {
        if (classesRepository.findClassesByClassNo(classNo) != null) {
            return classesRepository.findClassesByClassNo(classNo).getClassName();
        } else {
            return null;
        }
    }

}
